using Stetson.Emulator.Hardware;

namespace Stetson.Emulator {
	public partial class TI83Plus 
	{
		public void SendVariable(byte[] header, byte[] data)
		{
			try 
			{
				this.LinkPort.WritePacket(IOPort.MachineID.ComputerToTI83Plus,
				                          IOPort.CommandID.RequestToSendVariable, header);

				this.LinkPort.ReadExpectedPacket(IOPort.CommandID.Acknowledge);
				this.LinkPort.ReadExpectedPacket(IOPort.CommandID.ClearToSend);

				this.LinkPort.WritePacket(IOPort.MachineID.ComputerToTI83Plus,
				                          IOPort.CommandID.Acknowledge, null);
				this.LinkPort.WritePacket(IOPort.MachineID.ComputerToTI83Plus,
				                          IOPort.CommandID.Data, data);

				this.LinkPort.ReadExpectedPacket(IOPort.CommandID.Acknowledge);
				this.LinkPort.WritePacket(IOPort.MachineID.ComputerToTI83Plus,
				                          IOPort.CommandID.EndOfTransmittion, null);
			}
			catch 
			{
			}
		}
	}
}
